package edu.sctu.zhangwang.month201506.day20150618;

import sun.net.www.http.HttpClient;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user10 on 2015/6/19.
 */
public class InternetUtil {
    public void InterUtil(String path){
        String param = "page=1&size=10";
        int count = 0;
        byte[] bytes= new byte[1024];
        try {
            URL url = new URL(path);
            try {
                URLConnection urlConnection = url.openConnection();
                urlConnection.setDoOutput(true);
                urlConnection.connect();
                OutputStream out = urlConnection.getOutputStream();
                out.write(param.getBytes());
                out.close();

                InputStream input = urlConnection.getInputStream();
                while ((count=input.read(bytes))!=-1){
                    System.out.println(new String(bytes,0,count,"utf-8"));
                }
                input.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        InternetUtil internetUtil = new InternetUtil();
        internetUtil.InterUtil("http://api.ii.com.cn/goods/apprec");
    }

}
